from rest_framework.response import Response

from environments.models import Environment


def validate_env_id(env_id=None):
    if not env_id:
        return Response({"msg": "请求参数env必填", "data": None}, status=400)
    try:
        Environment.objects.get(id=env_id)
    except Environment.DoesNotExist:
        return Response({"msg": "参数env传入的为无效值", "data": None}, status=400)
    except Exception as e:
        return Response({"msg": f"环境查询异常: {str(e)}", "data": None}, status=500)
    return None  # 表示验证通过
